$('.selections-products.cms').livequery(function() {
	$('.cat-box h3').on('mouseenter mouseleave click mousedown', function(e) {
		var item = $(this);
		if(!item.hasClass('active')) {
			if(e.type == 'click') {
				var categoryProdList = item.closest('.cat-box').children('.prod-list');
				categoryProdList.slideDown(100, function(){$('.prod-list').clearQueue(); item.addClass('active')});
			}
			if(e.type == 'mouseenter') item.addClass('hover');
		}
		else if(e.type == 'click') {
			var categoryProdList = item.closest('.cat-box').children('.prod-list');
			categoryProdList.slideUp(100, function(){$('.prod-list').clearQueue(); item.removeClass('active')});
		}
		if(e.type == 'mouseleave') item.removeClass('hover');
		
		return false;
	});
	
	$('.cat-box .product').on('click', function(e) {
		self = $(this);
		if(self.hasClass('blocked')) return false;
		self.addClass('blocked');
		
		$.ajax({  
			type: "POST",  
			url: W_AJAX + "product/selections-adding",  
			data: {
				ID_selection: $('#id-selection').val(),
				ID_product: self.data('id')
			},
			dataType: "json",
			success: function(objData) {
				if (objData.result == 'OK') {
					$('.select-box.r .prod-list').prepend('<div class="product" data-id="' + objData.productData.id + '">' + objData.productData.name + '<img src="/content/images/icons/delete.png" class="del"></div>');
					self.remove();
				}
				else App.showError(objData.error);
				self.removeClass('blocked');
			}
		});
		return false;
	});
	
	$('.select-box.r').on('click', '.product .del', function(e) {
		self = $(this).closest('.product');
		if(self.hasClass('blocked')) return false;
		self.addClass('blocked');
		
		$.ajax({  
			type: "POST",  
			url: W_AJAX + "product/selections-deleting",  
			data: {
				ID_selection: $('#id-selection').val(),
				ID_product: self.data('id')
			},
			dataType: "json",
			success: function(objData) {
				if (objData.result == 'OK') self.remove();
				else {
					App.showError(objData.error);
					self.removeClass('blocked');
				}
			}
		});
		return false;
	});
});